import { createCommonPage } from '@/utils/service.js'

export const createForm = (userSource) => ({
  searchWords: '',
  userSource,  // 1 门户用户 2本系统用户
  ...createCommonPage(),
  // current: 1,
  // pageSize: Vue.prototype.commonPagination.size,
})

export const createColumns = (vm, page) => {
  return [
    { align: 'center', type: 'selection', width: 60 },
    {
      title: '序号',
      key: 'id',
      align: 'center',
      width: 80,
      render(h, params) {
        return <div>{(vm.formData.pageNo - 1) * vm.formData.pageSize + params.index + 1}</div>
      },
    },
    { title: '用户名', align: 'center', key: 'userName' },
    { title: '所属单位', align: 'center', key: 'organName' },
    { title: '登录名', align: 'center', key: 'userAccount' },
    { title: '初始密码', align: 'center', key: 'defaultPassword' },
    {
      title: '用户角色',
      align: 'center',
      key: '',
      render(h, params) {
        if (params.row.editable) {
          const i = params.index
          return <i-input value={vm.tableData[i].title} on-input={(val) => (vm.tableData[i].title = val)}></i-input>
        } else {
          return h('span', params.row.roleName || '')
        }
      },
    },
    {
      title: '操作',
      align: 'center',
      // width: page === 'provideUser' ? 240 : 180,
      width: 180,
      render(h, params) {
        const btnGroups = (
          <div class="table-oper">
            <i-button type="text" className="f12" nativeOnClick={() => vm.handleTableRowEdit(params.row)}>
              编辑
            </i-button>
            <poptip confirm transfer title="确定重置?" on-on-ok={() => vm.handleTableRowResetPwd(params.row)}>
              <i-button type="text" class="f12">
                重置密码
              </i-button>
            </poptip>
          </div>
        )
        // 供稿端用户可以删除，改为不可删除
        /* if (page === 'provideUser') {
          btnGroups.children.splice(1, 0,
            <poptip confirm transfer title="确定删除?" on-on-ok={() => vm.handleTableRowDelete(params.row)}>
              <i-button type="text" className="f12">
                删除
              </i-button>
            </poptip>,
          )
        } */
        return btnGroups
      },
    },
  ]
}

